<script setup>
import { ref, watch } from "vue";

const question = ref("");
const answer = ref("答案");
const loading = ref(false);

// 可以直接侦听一个 ref
watch(question, (newQuestion) => {
  if (newQuestion.includes("?")) {
    loading.value = true;
    answer.value = "Thinking...";
    setTimeout(() => {
      answer.value = "是的";
    }, 1000);
  }
});
</script>

<template>
  <p>
    提问问题
    <input v-model="question" :disabled="loading" />
  </p>
  <p>{{ answer }}</p>
</template>
